package cn.intotw.rdcj.core.bean;

import java.io.Serializable;

public class Result<T> implements Serializable {
    private boolean success;
    private String errcode;
    private String errmsg;
    private T result;

    public Result() {
    }



    public Result(String errcode, String errmsg) {
        this(errcode, errmsg, null);
    }

    public Result(String errcode, String errmsg, T result) {
        if (CommonErrors.SUCCESS.getCode().equals(errcode)) {
            this.success = true;
        }

        this.errcode = errcode;
        this.errmsg = errmsg;
        if (null != result) {
            this.result = result;
        }
    }
    public Result(boolean success, String errcode, String errmsg) {
        this.success = success;
        this.errcode = errcode;
        this.errmsg = errmsg;
    }

    public Result(boolean success, String errcode, String errmsg, T result) {
        this.success = success;
        this.errcode = errcode;
        this.errmsg = errmsg;
        this.result = result;
    }
    public static Result success(){
        return new Result(true,CommonErrors.SUCCESS.getCode(),CommonErrors.SUCCESS.getMsg());
    }
    public static <T> Result<T> successWithResult(T result){
        return new Result<T>(true,CommonErrors.SUCCESS.getCode(),CommonErrors.SUCCESS.getMsg(),result);
    }
    public boolean isSuccess() {
        return this.success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getErrcode() {
        return this.errcode;
    }

    public void setErrcode(String errcode) {
        this.errcode = errcode;
    }

    public String getErrmsg() {
        return this.errmsg;
    }

    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }

    public T getResult() {
        return this.result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    @Override
    public String toString() {
        return "Result{" +
                "success=" + success +
                ", errcode='" + errcode + '\'' +
                ", errmsg='" + errmsg + '\'' +
                ", result=" + result +
                '}';
    }
}